Differential Equations and Numerical Calculus

Bren Calculus Workshop


Nathaniel Grimes

Bren School of Environmental Science & Management

Last updated: Sep 24, 2024

  1. Take the Integrals

\[ \begin{align} \text{A) }y=\frac{3}{x^2}, y(0)=5& &\text{B) }g(t)=3t^5-2t^3+16t-7 & &\text{C) } \int^4_2\frac{1}{2}x \end{align} \]

  1. A model for the rate of change in ozone concentrations over time between 1962-1984 is given by \(\frac{dC}{dt}=2t+20\). Where \(C\) is the ozone concentration (ppm) and t is the elapsed time in years. Given that in 1964 the ozone concentration was 30 ppm, what was the ozone concentration in 1982?

Exponent rules in Integration


\[ \large \int e^xdx=e^x+C \]


  • If the x term gets more complex, we need integration by parts or substitution. Very Complicated and We will not cover!

  • Numerical Calculus will handle this for us

Natural Logs in Integration


\[ \large \int \frac{1}{x}=\ln x+C \]

\[ \begin{align} \int \ln x&=x\ln x-x+C \end{align} \]


  • No easy chain rule equivalent in Integration

  • This is solved by integration by parts

Differential Equations help us study how things interact together over time


X and Y are not independent, they change with each other

\[ \large \frac{dy}{dx}=4y+2x \]

  • What are taking the integral with respect too?


  • What do we do with the 4y?


  • What about the dy?

Differential Equations help us understand changing environments


  • Variables often change with each other and affects over time are extremely important

Predator-Prey Dyanmics are classic ecological cases of differential equations


Differential Equations are systems in motion


Groundwater velocity


We can use phase diagrams to understand the system


  • Find isoclines (where \(dy/dx=0\))

  • Determine the direction of the flow

  • Find the equilibrium points

  • Determine the stability of the equilibrium points

Steps to Solving ODEs


  1. Move like terms to the same side, including differentials (dx,dy)

  2. Apply the integral to both sides

  3. Rearrange equations to isolate in terms of dependent variable

  4. Use initial conditions (if given) to find C values

  5. Evaluate the bounds if definite intervals are given

Practice Differential Equations


\[ \frac{dy}{dx}=4y \]

\[ \frac{dy}{4y}=dx \]

\[ \begin{align} \int\frac{dy}{4y}&=\int dx\\ \frac{1}{4}\ln y&=x+C_1 \\ \ln y&=4x+C_2\\ y&=e^{4x+C_2} \\ y&=e^{C_2}e^{4x} \\ y&=Ce^{4x} \end{align} \]

Team Assessment

An oil spill of the coast of Santa Barbara is spreading rapidly. Previous spills and an analysis of the current indicate that the oil is spreading at a daily rate of:

\[ \frac{dA}{dt}=-0.001A+60 \]

Where A is the area of the oil spill in \(km^2\) and t is the time in days.

If after the first day the oil has spread to 25 \(km^2\), find an equation to show the spread of oil in total area.

When will the oil spill cover all of the Santa Barbara Channel (~5850 \(km^2\))?

Hint:(The integral of \(\frac{1}{ax+b}=\frac{ln(ax+b)}{a}\) Think reverse chain rule)

Numerical Calculus

Functions in R


  • Like functions in math, R functions are like baking recipes
#cake       #recipe name (Ingredients)
output    <-  mean         (x,...)



x<-mean(1:5,na.rm=TRUE)
x
[1] 3
  • But where are the steps?

All functions have documentation


  • Any built in function in R describes the function and how to use it


?seq


  • Use Google to have more intuitive explanations


We can make our own functions


#Name i will give   Tell R we want to     Ingredients
#my function        make a function      List
my_first_fun       <-  function        (x,a)   {
  
  # Steps
  y=x+2*a
  
  return(y)  #The cake output
  
} # End the function steps


my_first_fun(x=1,a=2)
[1] 5

Key pieces of R functions


  1. Name - What are we going to call our function?


  1. Ingredients - What goes into our function


  1. Steps - All the instructions we apply within our function contained within \(\{\}\)

    • Order of steps matter (i.e. can’t evaluate z=w+x if x or w have not been created)


  1. Output - What do we want the function to put out? (By default it is the last object, explicit with return())

Can you arrange this function into the correct order?


b=(a+x)*y
}
a=x+y
add_multiply<-function(x,y){
  return(b)

Solution


add_multiply<-function(x,y){
  
  a=x+y
  
  b=(a+x)*y
  
  return(b)
}